﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="DHGMS Solutions" file="NonQuery.cs">
//   2004-2012 DHGMS Solutions. Some Rights Reserved. Licensed under GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Dhgms.TplHelper.Controller.Task.Sql
{
    using System.Data.Common;

    using Dhgms.DataManager.Model.Helper.Database;
    using Dhgms.TplHelper.Model.Info.TaskResult;

    /// <summary>
    /// Base class for handling an SQL task
    /// </summary>
    /// <typeparam name="TDatabaseHelperClass">
    /// The DB Helper Class used for commands
    /// </typeparam>
    /// <typeparam name="TParameterClass">
    /// The .NET DB Parameter Type
    /// </typeparam>
    public abstract class NonQuery<TDatabaseHelperClass, TParameterClass> :
        Base<SingleResultInteger32, TDatabaseHelperClass, TParameterClass>
        where TDatabaseHelperClass : DatabaseHelperBase<TParameterClass>, new()
        where TParameterClass : DbParameter
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="NonQuery{TDatabaseHelperClass,TParameterClass}"/> class. 
        /// </summary>
        /// <param name="taskName">
        /// The name of the task
        /// </param>
        /// <param name="connectionString">
        /// Database Connection String
        /// </param>
        protected NonQuery(string taskName, string connectionString)
            : base(taskName, connectionString)
        {
        }

        #endregion

        #region Methods

        /// <summary>
        /// The OnProcess event for doing the donkey work
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        protected override void OnProcess(SingleResultInteger32 result)
        {
            this.DbHelper.ProcessNonQuery(this.ConnectionString, this.GetSql(), this.GetParameters(), false);
        }

        #endregion
    }
}